# -*- coding: utf-8 -*-

##@package RTMoteReader
# @author Bretton Murphy
# @date Spring 2011
#
# This module reads in wireless sensor data at real time.  Simply by specifing a sensor type
# and a mote id the most recent data for the sensor and mote id is returned.
#
# This class is a placeholder for a possible future real time mote reader.
# The future version will connect to a server which will constantly update
# the values of the sensors for the desired motes.

from DBMoteReader import DBMoteReader

##The reference to the DBMoteReader
dbMoteReader = None

##Gets the most recent data for a given sensor
#
# Given a sensor type and mote id the most recent data is return for that sensor type.
#
# @param sensor The sensor whose data is to be returned, a string.
# @param mote_id The mote sensor id whom the sensor belongs to
# @return A recent sensor reading value
#
def getSensorData(sensor, mote_id):
    
    global dbMoteReader

    #First make sure that we have a DBMoteReader object and it's connected to a database
    #If so then get and return the value 
    if dbMoteReader == None:
        dbMoteReader = DBMoteReader()
    if not dbMoteReader.isConnected():
        dbMoteReader.connectToDB()
    #else:
        value = dbMoteReader.getSensorData(sensor, mote_id)
        return value
    
